<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>SeriesSum</title>
</head>
<body>
  <script type="text/javascript">
    const Series = [{
      name: 'Web',
      courses: [{
        name: 'HTML',
        lessons: [{
          name: 'HTML Lesson 1'
        },{
          name: 'HTML Lesson 2'
        },{
          name: 'HTML Lesson 3'
        }]
      },{
        name: 'CSS',
        lessons: [{
          name: 'CSS Lesson 1'
        },{
          name: 'CSS Lesson 2'
        },{
          name: 'CSS Lesson 3'
        },{
          name: 'CSS Lesson 4'
        }]
      },{
        name: 'JavaScript',
        lessons: [{
          name: 'JavaScript Lesson 1'
        },{
          name: 'JavaScript Lesson 2'
        }]
      }]
    },{
      name: 'PHP',
      courses: [{
        name: 'Linux',
        lessons: [{
          name: 'Linux Lesson 1'
        },{
          name: 'Linux Lesson 2'
        }]
      },{
        name: 'MySQL',
        lessons: [{
          name: 'MySQL Lesson 1'
        },{
          name: 'MySQL Lesson 2'
        },{
          name: 'MySQL Lesson 3'
        },{
          name: 'MySQL Lesson 4'
        }]
      },{
        name: 'Nginx',
        lessons: [{
          name: 'Nginx Lesson 1'
        },{
          name: 'Nginx Lesson 2'
        },{
          name: 'Nginx Lesson 3'
        },{
          name: 'Nginx Lesson 4'
        }]
      }]
    }]

     function seriesSum(Series){
      // 返回每个系列名称，及每个系列一共有多少个课（lesson 的总数）;
      var arr = []  // 用来存储 每一个系列 eg: [ {name:"web", count:9}, ... ] 
      for(var i = 0; i < Series.length; i++){
        var obj = {}  // {name:'xxx', count:x}
        var count = 0  // 用来存储 一个大系列中到底有几个 lesson
        var series = Series[i];  // 每一个大系列，eg: Web和PHP 两个大系列
        for(var j = 0 ; j < series['courses'].length; j++){
          // 每个小系列 eg: html系列的lessons长度
          var lessons_count = series['courses'][j]['lessons'].length  
          count += lessons_count
        }
        // 组装 obj
        obj.name = Series[i]['name']
        obj.count = count
        // console.log(obj)
        arr.push(obj)
      }
      return arr;
    }
    let result = seriesSum(Series);
    console.log(result);
  </script>
</body>
</html>